package pers.test.votemanage.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import pers.test.votemanage.controller.response.CommResponse;
import pers.test.votemanage.domain.Options;
import pers.test.votemanage.domain.Question;
import pers.test.votemanage.domain.dto.QuestionDTO;
import pers.test.votemanage.exception.CommException;
import pers.test.votemanage.service.OptionsService;
import pers.test.votemanage.service.QuestionService;

@RestController
@Api(tags = "选项控制层")
public class OptionsController {

    @Autowired
    private OptionsService optionsService;

    @Autowired
    private QuestionService questionService;

    @ApiOperation(value = "创建题目选项",notes = "创建题目选项")
    @PostMapping("/createOptions")
    public CommResponse createOptions(@RequestBody Options options){
        QuestionDTO question = questionService.queryQuestion(options.getQuestionId());
        if(question == null){
            throw new CommException("9999","题目不存在");
        }else{
            optionsService.insertOptions(options);
        }
        return CommResponse.success();
    }
}
